package com.bysj.money_diary;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

@SuppressLint("Instantiatable")
public class Beizhu extends Dialog implements OnClickListener {

	private Button queding, quxiao;
	private EditText et;
	private Context context;
	private View v;

	// 
	public Beizhu(Context context,String beizhuString) {
		super(context, R.style.beizhu);
		this.context = context;
		View diaView = View.inflate(context, R.layout.jiyibi_beizhu, null);
		this.setContentView(diaView);
		this.v = diaView;
		
		et = (EditText) diaView.findViewById(R.id.jiyibi_beizhu_et);
		
		queding = (Button) diaView.findViewById(R.id.jiyibi_beizhu_queding);
		//
		quxiao = (Button) diaView.findViewById(R.id.jiyibi_beizhu_quxiao);
		et.clearFocus();
		queding.setOnClickListener(this);
		quxiao.setOnClickListener(this);
		this.show();
		diaView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.push_left_in));
		if("".equals(beizhuString)){
		    et.setHint("�����뱸ע����...");
		}else{
		    et.setText(beizhuString);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.jiyibi_beizhu_queding:
			//
				String content = et.getText().toString().trim();
				if (content.length() > 0) {
					hidden();
					Message msg  =Message.obtain();
					msg.what=Jiyibi.beizhu_msg;
					msg.obj = content;
					Jiyibi.mh.sendMessage(msg);
				} else {
					Toast.makeText(context, "添加备注", 1000).show();
				}
			break;
		case R.id.jiyibi_beizhu_quxiao:
			et.setText("");
			hidden();
			break;
		}
	}
	
	/*
	 * 
	 * */
	public void hidden(){
		this.v.startAnimation(AnimationUtils.loadAnimation(context, R.anim.push_left_out));
		new Thread() {
			public void run() {
				try {
					Thread.sleep(250);
					Beizhu.this.dismiss();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}.start();
	}
	
}
